/**   
 *  Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 * @Title: ActionUpdater.java 
 * @Package binder.action.support 
 * @Description: TODO
 * @author dailey_dai  
 * @date Apr 3, 2012
 * @version V1.0   
 */
package binder.action.support;

import java.util.Map;
import java.util.Observable;
import java.util.concurrent.ConcurrentHashMap;

import binder.model.BindBeanContext;

/**
 * @author dailey_dai
 * 
 */
public abstract class ActionUpdater extends Observable implements BindBeanContext {
	private Map<Object, Object> context = new ConcurrentHashMap<Object, Object>();
	private static final String DEFAULT_PROPERTY_NAME = "ACTION_EVENT_PROPERTY_~`!@_#$%^_&*()";

	/*
	 * (non-Javadoc)
	 * 
	 * @see binder.model.BindBeanContext#getProperty(java.lang.String)
	 */
	@Override
	public Object getProperty(Object propertyName) {
		return context.get(propertyName);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see binder.model.BindBeanContext#setProperty(java.lang.String,
	 * java.lang.Object)
	 */
	@Override
	public void setProperty(Object propertyName, Object value) {
		context.put(propertyName, value);
	}

	/* (non-Javadoc)
	 * @see binder.model.BindBeanContext#getDefaultProperty()
	 */
	@Override
	public Object getDefaultProperty() {
		return getProperty(DEFAULT_PROPERTY_NAME);
	}

	protected void update(Object e) {
		setChanged();
		registerConext(e);
		notifyObservers(e);
	}

	/**
	 * @param e
	 */
	protected void registerConext(Object e) {
		if (e == null)
			return;
		setProperty(this.getClass(), e);
		setProperty(e.getClass(), e);
		setProperty(DEFAULT_PROPERTY_NAME, e);
	}
}
